package com.zbkj.crmeb.merchant.api.controller;


import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.store.model.OrderInfoDelivery;
import com.zbkj.crmeb.store.request.DeliveryRequest;
import com.zbkj.crmeb.store.request.OrderInfoDeliveryRequest;
import com.zbkj.crmeb.store.response.DeliveryResponse;
import com.zbkj.crmeb.store.service.OrderInfoDeliveryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 查询万维快递
 * @author cyz
 * @date 2021/4/12 19:22
 */
@Slf4j
@RestController("MerOrderInfoDeliveryController")
@RequestMapping("api/front/mer/delivery")
@Api(tags = "查询万维快递")
public class FontOrderInfoDeliveryController {

    @Autowired
    private OrderInfoDeliveryService orderInfoDeliveryService;


    /**
     * 
     * @author cyz
     * @date 2021/4/12 19:25
     * @param request 
     * @return com.crmeb.core.common.CommonResult<com.zbkj.crmeb.store.response.DeliveryResponse>
     */
    @ApiOperation(value = "查询物流信息")
    @RequestMapping(value = "/queryShowApi", method = RequestMethod.GET)
    public CommonResult<DeliveryResponse> queryShowApi(@Validated DeliveryRequest request){
        if(Objects.isNull(request.getId())){
            return CommonResult.failed("物流id必传!");
        }
        OrderInfoDelivery orderInfoDelivery = orderInfoDeliveryService.getById(request.getId());
        if(null == orderInfoDelivery){
            return CommonResult.failed("暂无物流信息!");
        }
        request.setPhone(orderInfoDelivery.getPhone());
        request.setCom(orderInfoDelivery.getDeliveryCode());
        request.setDeliveryNumber(orderInfoDelivery.getDeliveryNumber());
        request.setOrderInfoId(orderInfoDelivery.getOrderInfoId());
        return CommonResult.success(orderInfoDeliveryService.queryDeliveryByShowApi(request, orderInfoDelivery));
    }


    /**
     * 
     * @author cyz
     * @date 2021/4/12 19:33
     * @param request 
     * @return com.crmeb.core.common.CommonResult<java.util.List<com.zbkj.crmeb.store.model.OrderInfoDelivery>>
     */
    @ApiOperation(value = "查询物流分段信息")
    @RequestMapping(value = "/queryDeliveryList", method = RequestMethod.GET)
    public CommonResult<List<OrderInfoDelivery>> queryDeliveryList(@Validated OrderInfoDeliveryRequest request){
        return CommonResult.success(orderInfoDeliveryService.getDeliveryList(request));
    }

    @ApiOperation(value = "列表") //配合swagger使用
    @RequestMapping(value = "/user/queryDeliveryList", method = RequestMethod.GET)
    public CommonResult<List<OrderInfoDelivery>> getUserDeliveryList(@Validated OrderInfoDeliveryRequest request){
        return CommonResult.success(orderInfoDeliveryService.getUserDeliveryList(request));
    }

}



